<?php
class database{
	static $instance;
	public $_db;
	public $database;
	private function __construct(){
		$this->connectDb();
	}
	public function connectDb($host='',$user='',$pwd='',$database=''){
		if(!$host&&!$user&&!$pwd&&!$database){
			$autoload= new autoload();
			$configFile= simplexml_load_file($autoload->getConfig());
			$host =(string) $configFile->system->host;
			$user =(string) $configFile->system->user;
			$pwd =(string) $configFile->system->password;
			$database =(string) $configFile->system->database;
		}
		$con = mysql_connect($host,$user,$pwd);
		$this->_db=$con;
		$db = mysql_select_db($database,$con);
		if(!$db){
			require_once('install/install.php');
			$install=new install();
		}
		$this->query('SET NAMES utf8');
		return $this->_db;
	}
	public function query($sql){
		mysql_query($sql,$this->_db);
	}
	public static function getInstance(){
		if(!(self::$instance instanceof self)){
			self::$instance = new self();
		}
		return self::$instance;
	}
}
?>